﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithm
{
    public static class BubbleSort
    {
        /// <summary>
        /// 冒泡排序,原地排序，时间复杂度为n^2
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array"></param>
        public static void BubbleSortArray<T>(T[] array) where T:IComparable<T>
        {
            int length = array.Length;
            for (int i = 0; i < length; i++)
            {
                for (int j = length-1; j > i; j--)
                {
                    if (array[j].CompareTo(array[j-1]) < 0)
                    {
                        T tmp = array[j - 1];
                        array[j - 1] = array[j];
                        array[j] = tmp;
                    }
                }
            }
        }
    }
}
